package com.jurenzhao.partssystem.work.dayli.controller;

import com.jurenzhao.partssystem.work.dayli.entity.WorkAffiche;
import com.jurenzhao.partssystem.work.dayli.service.WorkAfficheService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/dayli")
public class WorkAfficheController {

    @Resource
    private WorkAfficheService workAfficheService;

    @RequestMapping("/list1")
    public String List(Model model){
        List<WorkAffiche> list1 = workAfficheService.findAll();
        model.addAttribute("list1",list1);
        return "work/dayli/list1";
    }

   @RequestMapping("/list/{affiId}")
    public String title(Model model,@PathVariable("affiId") int affiId){
      WorkAffiche workAffiche = workAfficheService.findById(affiId);
      model.addAttribute("workAffiche",workAffiche);
      return "work/dayli/list";
   }

    @RequestMapping("preadd")
    public String preadd(Model model){
            WorkAffiche workAffiche = new WorkAffiche();
            model.addAttribute("workAffiche",workAffiche);
            List<WorkAffiche> list = workAfficheService.findAll();
            model.addAttribute("list",list);
            return "work/dayli/add";
    }

    @RequestMapping("add")
    public String add(WorkAffiche workAffiche){
        workAfficheService.save(workAffiche);
        return "redirect:/dayli/list1";
    }

    @RequestMapping("/preupdate/{affiId}")
    public String preupdate(Model model, @PathVariable("affiId") int affiId){
        WorkAffiche workAffiche1 = workAfficheService.findById(affiId);
        model.addAttribute("workAffiche1",workAffiche1);
        List<WorkAffiche> list = workAfficheService.findAll();
        model.addAttribute("list",list);
        return "work/dayli/update";
    }


    @RequestMapping("update")
    public String update(WorkAffiche workAffiche){
        workAfficheService.updateSelect(workAffiche);
        return "redirect:/dayli/list1";
    }

    @RequestMapping("/delete/{affiId}")
    public String delete(@PathVariable("affiId") int affiId){
        workAfficheService.delete(affiId);
        return "redirect:/dayli/list1";
    }
}
